import requests
from api.ihrm_login_api import IhrmLoginApi

data = {"mobile": "13800000002", "password": "123456"}
resp1 = IhrmLoginApi.login(data)
token = resp1.json().get("data")

# 查询组织列表
resp2 = requests.get(url="http://ihrm-test.itheima.net/api/company/department",
                     headers={"Authorization": f"{token}"})
print(resp2.json())

#  由ID查询部门
id = "1495026161837711360"
resp3 = requests.get(url="http://ihrm-test.itheima.net/api/company/department/" + id,
                     headers={"Authorization": f"{token}"})
print(resp3.json())

# 添加部门
resp4 = requests.post(url="http://ihrm-test.itheima.net/api/company/department",
                      headers={"Authorization": f"{token}"},
                      json={"name": "上海测试27", "code": "952711111"})
print(resp4.json())

# 修改部门
resp5 = requests.put(url="http://ihrm-test.itheima.net/api/company/department/" + id,
                     headers={"Authorization": f"{token}"},
                     json={"name": "上海测试288", "code": "952711111"})
print(resp5.json())

# 删除部门
resp6 = requests.delete(url="http://ihrm-test.itheima.net/api/company/department/" + id,
                        headers={"Authorization": f"{token}"})
print(resp6.json())
